import { createRouter, createWebHistory } from "vue-router";
// import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "my",
    },
    {
      path: "/login",
      name: "login",
      component: () => import("@/views/login/index.vue"),
    },
    {
      path: "/reg",
      name: "reg",
      component: () => import("@/views/reg/index.vue"),
    },
    {
      path: "/my",
      name: "my",
      component: () => import("@/views/my/index.vue"),
    },
  ],
});
router.beforeEach((to, from, next) => {
  let isAuthenticated = localStorage.getItem("token");
  if (to.name == "my" && !isAuthenticated) next({ name: "login" });
  else next();
});
export default router;
